package com.yuezhu.sling;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.yuezhu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @创建人：zhaoshuzhen
 * @创建时间：2016/1/5 16:53
 */
public class SlingView extends LinearLayout  {
    private Context context;
    private ViewFlow viewFlow;
    private ImageAdapter imageAdapter;
    private List<String> list = new ArrayList<String>();

    public SlingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        View view = View.inflate(context, R.layout.sliping_layout, this);
        list.add("http://7xlwwd.com1.z0.glb.clouddn.com/yanwushu1.jpg");
        list.add("http://7xlwwd.com1.z0.glb.clouddn.com/yanwushu2.jpg");
        list.add("http://7xlwwd.com1.z0.glb.clouddn.com/yanwushu3.jpg");
        setSliping(view);

    }

    private void setSliping(View view) {
        viewFlow = (ViewFlow) view.findViewById(R.id.viewflow);
        imageAdapter = new ImageAdapter(context);
        imageAdapter.setSlingData(list);
        viewFlow.setAdapter(imageAdapter);
        viewFlow.setmSideBuffer(3); // 实际图片张数， 我的ImageAdapter实际图片张数为3

        CircleFlowIndicator indic = (CircleFlowIndicator) view.findViewById(R.id.viewflowindic);
        viewFlow.setFlowIndicator(indic);
        viewFlow.setTimeSpan(3000);
        viewFlow.setSelection(200); // 设置初始位置
        viewFlow.startAutoFlowTimer(); // 启动自动播放
    }


}
